<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>千园千变，万班万课</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="assets/css/admin.css">
    <link rel="stylesheet" href="assets/css/app.css">
    <link rel="stylesheet" href="assets/css/viewer.min.css">
</head>
<body data-type="generalComponents">
<div class="tpl-portlet-components">
    <div class="portlet-title">
        <ol class="am-breadcrumb">
            <li><a href="#" class="am-icon-home">首页</a></li>
            <li><a href="#">Amaze UI CSS</a></li>
            <li class="am-active">文字列表</li>
        </ol>
        <button class="refresh_btn"><i class="am-icon-refresh"></i></button>
    </div>
    <div class="tpl-block">
        <div class="am-g">
            <div class="am-u-sm-12 am-u-md-9">
                <div class="am-btn-toolbar">
                    <div class="am-btn-group am-btn-group-xs">
                        <button type="button" class="am-btn am-btn-default am-btn-success btn_add"><span
                                class="am-icon-plus"></span> 添加老师
                        </button>
                    </div>
                </div>
            </div>
            <div class="am-u-sm-12 am-u-md-3">
                <div class="am-input-group am-input-group-sm">
                    <input type="text" id="search" class="am-form-field" placeholder="请输入关键字">
                    <span class="am-input-group-btn">
                        <button class="am-btn  am-btn-default am-btn-success tpl-am-btn-success am-icon-search"
                                type="button" id="searchBtn"></button>
                    </span>
                </div>
            </div>
        </div>
        <div class="am-g">
            <div class="am-u-sm-12">
                <table class="am-table am-table-striped am-table-hover table-main" id="table">
                    <thead>
                    <tr>
                        <th class="table-id" width="120">ID</th>
                        <th class="table-title">账号</th>
                        <th class="table-type">姓名</th>
                        <th class="table-type">身份证正/反面</th>
                        <th class="table-set" width="180">操作</th>
                    </tr>
                    </thead>
                    <tbody></tbody>
                </table>
                <div class="am-cf">
                    <div class="am-fr">
                        <div class="am-pagination tpl-pagination" id="pagination"></div>
                    </div>
                </div>
                <hr>
            </div>
        </div>
    </div>
</div>
<div class="am-g tpl-amazeui-form model_panel" id="editPasswordPanel" style="display: none">
    <div class="am-u-sm-12">
        <form class="am-form am-form-horizontal">
            <div class="am-form-group">
                <label class="am-u-sm-3 am-form-label">学校名称</label>
                <div class="am-u-sm-9 line">
                    <b id="school_name" class="am-form-label"></b>
                </div>
            </div>
            <div class="am-form-group">
                <label class="am-u-sm-3 am-form-label">账号</label>
                <div class="am-u-sm-9 line">
                    <input type="number" id="username" name="username" style="width: 300px" placeholder="输入登录账号">
                </div>
            </div>
            <div class="am-form-group">
                <label for="one_pwd" class="am-u-sm-3 am-form-label">密码</label>
                <div class="am-u-sm-9">
                    <input type="password" id="one_pwd" name="one_pwd" style="width: 300px" placeholder="输入密码">
                </div>
            </div>
            <div class="am-form-group">
                <label for="two_pwd" class="am-u-sm-3 am-form-label">确认密码</label>
                <div class="am-u-sm-9">
                    <input type="password" id="two_pwd" name="two_pwd" style="width: 300px"
                           placeholder="输入确认密码">
                </div>
            </div>
        </form>
    </div>
</div>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/amazeui.min.js"></script>
<script src="assets/js/layer.js"></script>
<script src="assets/js/jquery.cookie.js"></script>
<script src="assets/js/md5.min.js"></script>
<script src="assets/js/jquery.pagination.js"></script>
<script src="assets/js/jquery.serializejson.min.js"></script>
<script src="assets/js/request.js"></script>
<script src="assets/js/verification.js"></script>
<script src="assets/js/viewer.min.js"></script>
<script src="assets/js/app.js"></script>
</body>
<script>
var loginData=JSON.parse($.cookie('loginData'))
var page = '1'
var size = '10'
var search = ''
var type = ''
var classV = ''
var val = ''
var total = 0
var listData=null
function getDataList (callback) {
  AjaxRequest({
    url: '/agent/teacher_list/',
    data: {page,size,search},
    succFun: function (res) {
      var data = res.data
      total = data.count
      var html = ''
      listData=res.data.list
      listData.forEach(function (d, i) {
        html += ` <tr>
                    <td>${d.admin_id}</td>
                    <td><a href="#" class="btn_edit"   data-id="${d.admin_id}">${d.username}</a></td>
                    <td>${d.name||'--'}</td>
                    <td class="card_content">
                        <p><img  src="${d.id_url[0]}" alt=""></p>
                        <p><img  src="${d.id_url[1]}" alt=""></p>
                    <td>
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">
                                <button class="am-btn am-btn-success am-btn-xs btn_edit" data-id="${d.admin_id}" >
                                    <span class="am-icon-pencil-square-o"></span> 编辑
                                </button>
                                <button class="am-btn am-btn-default am-btn-xs am-text-danger btn_delete"  data-id="${d.admin_id}" >
                                    <span class="am-icon-trash-o"></span> 删除
                                </button>

                            </div>
                        </div>
                    </td>
                </tr>`
      })
      $('#table tbody').html(html)
      callback && callback()
    }
  })
}
function init () {
  getDataList(function () {
    $('#pagination').pagination({
      pageCount: Math.ceil(total / size),
      jump: true,
      coping: true,
      keepShowPN: true,
      prevContent: '«',
      nextContent: '»',
      jumpBtnCls: 'am-btn am-btn-primary',
      activeCls: 'am-active',
      callback: function (api) {
        page = api.getCurrent().toString()
        getDataList()
      }
    });
  })
}
init()
var ids = []
$('table').on('change', 'tbody [type="checkbox"]', function () {
  ids = []
  var $tableTbody = $('table tbody [type="checkbox"]')
  $tableTbody.each(function (i, d) {
    if ($(d).prop('checked')) {
      ids.push($(this).val())
    }
  })
  if ($tableTbody.length === ids.length) {
    $('table thead [type="checkbox"]').prop('checked', true)
  } else {
    $('table thead [type="checkbox"]').prop('checked', false)
  }
})
$('table thead [type="checkbox"]').change(function () {
  ids = []
  var isChecked = $(this).prop('checked')
  $('table tbody [type="checkbox"]').each(function (i, d) {
    if (isChecked) {
      $(d).prop('checked', true)
      ids.push($(this).val())
    } else {
      $(d).prop('checked', false)
    }
  })
})
//修改或新增
$('body').on('click', '.btn_edit,.btn_add', function (e) {
  e.preventDefault()
  let id = $(this).attr('data-id')
  location.href = 'teacher_update_or_add.html?id=' + id
})
//搜索
$('#searchBtn').click(function (e) {
  e.preventDefault()
  search = $('#search').val().toString()
  page = '1'
  init()
})
//修改密码
$('body').on('click', '.btn_edit_password', function (e) {
  e.preventDefault()
  let school_id = $(this).attr('data-id')
  let school_name = $(this).attr('data-name')
  let userName = $(this).attr('data-username')
  $('#school_name').html(school_name)
  $('#username').val(userName)
  layer.open({
    type: 1,
    title: '修改账号密码',
    area: ['500px', '380px'],
    shadeClose: true, //点击遮罩关闭
    btn: ['确定', '取消'],
    content: $('#editPasswordPanel'),
    yes: function () {
      if (Verification()) {
        var formData = $('#editPasswordPanel form').serializeJSON()
        formData.school_id = school_id
        AjaxRequest({
          url: '/admin/school_set/',
          data: formData,
          succFun: function (res) {
            layer.msg(res.message, {icon: 1, time: 1500}, function () {
              layer.closeAll()
              getDataList()
            })
          }
        })
      }

    }
  });
})
//查看图
$('table').on('click','.card_content img',function () {
  $(this).viewer();
})
//删除
$('table').on('click', '.btn_delete', function () {
  let admin_id = $(this).attr('data-id')
  layer.confirm('确认要删除该条记录吗？', {
    btn: ['确定', '取消'] //按钮
  }, function () {
    AjaxRequest({
      url: '/agent/del_teacher/',
      data: {admin_id},
      succFun: function (res) {
        layer.msg(res.message, {icon: 1})
        getDataList()
      }
    })
  });
})
</script>
</html>